﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HanGu.Services.Interface;
using HanGu.Entity;

namespace HanGu.Services
{
    public class FileManageService : BaseService, IFileManage
    {

        public List<FileManage> GetAll()
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.FileManage.ToList();
            }
        }

        public FileManage GetByID(int id)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.FileManage.Where(c => c.ID == id).FirstOrDefault();
            }
        }

        public FileManage GetByID(string guid)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.FileManage.Where(c => c.GUID == guid).FirstOrDefault();
            }
        }
        public List<FileManage> GetByGroupName(string guid)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.FileManage.Where(c => c.GroupName == guid).ToList();
            }
        }
        public List<FileManage> GetByGuid(string guid)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.FileManage.Where(c => c.GUID == guid).ToList();
            }
        }
        public bool Add(FileManage model)
        {
            try
            {
                this.Add<FileManage>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Update(FileManage model)
        {
            try
            {
                this.Update<FileManage>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Delete(string guid)
        {
            try
            {
                this.Delete<FileManage>(c => c.GUID == guid);
                return true;
            }
            catch { return false; }
        }
        public bool DeleteByID(int id)
        {
            try
            {
                this.Delete<FileManage>(c => c.ID == id);
                return true;
            }
            catch { return false; }
        }
        public bool DeleteByGroupName(string guid)
        {
            try
            {
                this.Delete<FileManage>(c => c.GroupName == guid);
                return true;
            }
            catch { return false; }
        }
        public bool DeleteByGuid(string guid)
        {
            try
            {
                this.Delete<FileManage>(c => c.GUID == guid);
                return true;
            }
            catch { return false; }
        }
    }
}
